<script>
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;

var idbRequest = window.webkitIndexedDB.open('tododb');
idbRequest.onsuccess = function(e) {
	var db = this.result;
	if (db.version!="v0") {
		db.setVersion("v0").onsuccess = function (e) {
			db.createObjectStore('todo','timeStamp',true).onsuccess = function(e1) {
				console.log('created objectstore');
			}
		}
	} else {
		var transaction = db.transaction(['todo'], IDBTransaction.READ_WRITE);
		console.log(transaction);
		var objStore = transaction.objectStore('todo');
		console.log(objStore);
		
		var dat = {"foo":"bar","timeStamp":"today"};
		var writeReq = objStore.add(dat);
		writeReq.onerror = function (e) {
			writeReq.abort();
		}
		writeReq.onComplete = function(e) {
			console.log("write complete");
		}
		
		var readCursor = objStore.openCursor();
		readCursor.onsuccess = function(e) {
			if (e.result) {
				console.log(e.result);
			} else {
				console.log('end');
			}
		}
	}

};
</script>